package com.zj.mq.demo.controller;

import com.zj.mq.demo.common.Result;
import com.zj.mq.demo.entity.Order;
import com.zj.mq.demo.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/order")
@RestController
public class OrderController {

    @Autowired
    private OrderService orderService;

    @PostMapping("/")
    public Result addOrder(Order order) {
        return Result.success(orderService.addOrder(order));
    }

    @PostMapping("/pay/{id}")
    public Result payOrder(@PathVariable("id") Integer id) {
        return Result.success(orderService.pay(id)?"支付成功":"订单已经过期");
    }

    @GetMapping("/canceled/{username}")
    public Result canceledOrder(@PathVariable("username") String username) {
        return Result.success(orderService.timeoutCancelOrder(username));
    }

}
